package rpcserverimpl

import (
	"errors"
	"context"
	"grpc_etcd/proto"
)

/**
rpc相关服务接口的具体实现
 */
var students = map[int64]proto.Student{
	1:proto.Student{Id:1,Name:"ztind",Age:18,Sex:proto.Sex_man},
	2:proto.Student{Id:2,Name:"jimmy",Age:18,Sex:proto.Sex_woman},
	3:proto.Student{Id:3,Name:"tom",Age:18,Sex:proto.Sex_man},
	4:proto.Student{Id:4,Name:"jack",Age:18,Sex:proto.Sex_woman},
}

type StudentManage struct {
	ServerAddress string
}

func (this *StudentManage)GetStudent(_ context.Context,in *proto.ReqStudent) (out *proto.Student,err error){
	student := students[in.Id]
	if student.Id == 0{
		return nil,errors.New("此学生不存在！")
	}
	student.Name = student.Name + " "+this.ServerAddress
	return &student,nil
}

